new Vue({
	el: '#app',
	data: {
		uid: '',
		oid: '',
		cid: '',
		price: '',
		alipay_info: '',
		study: '',
		study_order: '',
		status: ''
	},
	mounted: function() {
		console.log("mounted end");
		this.init();
	},
	methods: {
		//关闭本页面
		close: function() {
			api.closeWin();
		},
		init: function() {
			var self = this;
			self.uid = $api.getStorage('uid');
			self.api_token = $api.getStorage('api_token');
			apiready = function() {
				var fid = api.pageParam;
				self.oid = fid.oid;
				self.status = fid.status;
				console.log(self.oid);
				//loading加载
				self.isS();
				//监听来自native的事件
				api.addEventListener({
					name: 'alipay_result'
				}, function(ret) {
					if(ret.value.code == 0) {
						api.openWin({
							name: 'my-order',
							url: '../user/myOrder.html',
							vScrollBarEnabled: false,
							reload: true
						});
					} else {

					}
				});
			}
		},
		isS: function() {
			var self = this;
			var UILoading = api.require('UILoading');
			if(self.isShow) {
				console.log(self.loadingId);
				UILoading.closeFlower({
					id: self.loadingId
				});
			} else {
				UILoading.flower({
					center: {
						x: api.winWidth / 2.0,
						y: api.winHeight / 2.0
					},
					size: 30,
					fixed: true
				}, function(ret) {
					console.log(JSON.stringify(ret));
					self.loadingId = ret.id;
				});
				self.getOrderMsg();
			}
		},
		//获取订单信息
		getOrderMsg: function() {
			var self = this;
			var data = {
				uid: self.uid,
				study_order_id: self.oid
			};
			$.post(base + config.study_view_order, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.study_order = msg.study_info.study_order;
					self.study = msg.study_info.study
					self.isShow = true;
					self.isS();
				} else {
					self.isShow = true;
					self.isS();
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//获取支付宝需要
		getMsg: function(oid) {
			var self = this;
			console.log(self.oid);
			var data = {
				uid: self.uid,
				study_order_id: oid
			};
			$.post(base + config.pay_mobile, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.price = msg.price;
					self.alipay_info = msg.alipay_info;
					self.send(self.price, self.alipay_info);
				} else {
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//立即付款
		buy: function() {
			console.log(this.oid);
			this.getMsg(this.oid);
		},
		//
		send: function(price, alipay_info) {
			api.sendEvent({
				name: 'submitOrder',
				extra: {
					price: price,
					alipay_info: alipay_info
				}
			});
		}
	}
})